package com.xq.service.impl;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.xq.utils.MD5Sign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class UserAuthServiceImpl {

    @Value("${msx.merId}")
    private String merId;

    @Value("${msx.appSercret}")
    private String appSercret;

    public String identityAuth(String name,String cardId,String base64FrontPic){
        String url ="http://127.0.0.1:8080/api/common/identityAuth";
        Map<String,Object> map = Maps.newHashMap();
        map.put("merId",merId);
        map.put("name",name);
        map.put("cardId",cardId);
        map.put("base64FrontPic",base64FrontPic);
       // map.put("sign", MD5Sign.sign(map,"aea43111aa87807fb79939b28256b929"));
        //String str = HttpUtil.post(url,map);
        String str = HttpUtil.createPost(url).body(JSON.toJSONString(map)).execute().body();
        log.info("身份认证返回结果："+str);
        return str;
    }

    public String liveAuth(String base64LivePic){
        String url ="http://127.0.0.1:8080/api/common/liveAuth";
        Map<String,Object> map = Maps.newHashMap();
        map.put("merId",merId);
        map.put("base64LivePic",base64LivePic);
        // map.put("sign", MD5Sign.sign(map,"aea43111aa87807fb79939b28256b929"));
        String str = HttpUtil.post(url,map);
        log.info("活体认证返回结果："+str);
        return str;
    }

    @Autowired
    private Environment environment;
    @PostConstruct
    public void init(){
        String s = environment.getProperty("my.test");
        String b= environment.getProperty("my.pro");
        System.out.println("结果:"+s+" "+b);
        //identityAuth("张三","1421411213","23424242432");
    }
}
